<template>
  <div class="activity-box">
    <div class="content-box">
      <BannerSwiper />
      <ActivityList :list="activityData" @changeNav="handleTagChange" />
      <div class="more-btn" v-if="!(start === maxPage)" @click="loadMore">加载更多内容…</div>
      <div class="nodata" v-if="start === maxPage">到底了...</div>
    </div>
  </div>
</template>

<script>
import BannerSwiper from '@/components/BannerSwiper';
import ActivityList from '@/views/activity/components/ActivityList';
import { articlesList, advertsList } from '@/api/api';

export default {
  components: {
    BannerSwiper,
    ActivityList,
  },
  data() {
    return {
      activityData: [],
      start: 0,
      maxPage: 0,
      activeTag: ''
    }
  },
  mounted() {
    this.getTopBanner();
    this.getActivityList();
  },
  methods: {
    // 加载更多
    loadMore() {
      if (this.start < this.maxPage) {
        this.start++;
        this.getZXList();
      }
    },
    // 获取活动列表
    async getActivityList(tagId) {
      const params = {
        status: 1,
        type: 'HD'
      }
      if (tagId) {
        params.categoryId = tagId;
      }
      const res = await articlesList(params);
      this.maxPage = Math.floor(res.count / 20);
      this.activityData = this.activityData.concat(res.list);
    },
    // 获取top banner
    async getTopBanner() {
      const params = {
        type: 'TOP',
        pageType: 'HD_PAGE',
        status: 1
      };
      const res = await advertsList(params);
      console.log(res);
    },
    // 活动分类改变时
    handleTagChange(tagId) {
      this.activityData = [];
      this.getActivityList(tagId);
    }
  }
}
</script>

<style lang="scss" scoped>
.activity-box {
  .content-box {
    padding-top: 20px;
    background: #F1F1F1;
    padding-bottom: 72px;
    .more-btn {
      width: 200px;
      height: 48px;
      line-height: 48px;
      background: #FFFFFF;
      border-radius: 4px;
      border: 1px solid #D8D8D8;
      margin: 32px auto 0;
      text-align: center;
      font-size: 16px;
      
      font-weight: 400;
      color: #4C4C4C;
      cursor: pointer;
      &:hover, &:active {
        opacity: 0.8;
      }
    }
    .nodata {
      width: 100%;
      text-align: center;
      margin: 60px 0 40px;
      color: #C0C4CC;
    }
  }
}
</style>